<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
  </head>
  <body>
    <script>
      var arr = ['阿里巴巴', '百度', '腾讯', '网易', '字节跳动']
      // es5  for(var i=0;i<8;i++){}  while {}   do{} while()   for in

      //es6 1  forEach  数组循环操作
      var arr2 = []
      var company = arr.forEach(ele => {
        // ele--数组每一项
        arr2.push(ele + '公司')
      })
      console.log(arr)
      console.log(arr2)
      // 2 map  循环数组  ele 当前数组项  inedx 当前数组项下标
      // 返回循环处理后的数组
      var jituan = arr.map((ele, index) => {
        console.log(ele, index)
        if (index % 2 == 0) {
          return ele + '集团'
        } else {
          return ele
        }
      })
      console.log(arr)
      console.log(jituan)
      //3 filter() 循环数组
      //返回新的数组  返回符合条件的数组项
      var farr = arr.filter((ele, index) => {
        if (index % 2 == 0) {
          return ele
        }
      })
      console.log(arr)
      console.log(farr)
      // for of  循环数组和对象
      var obj = {
        0: '小李',
        1: '男',
        2: '180',
        length: 3
      }
      //for in  x 代表下标
      for (let x in arr) {
        console.log(x)
      }
      // 循环数组
      for (let k of arr) {
        console.log(k) //k代表数组项
      }
      console.log(Array.from(obj))
      for (let m of Array.from(obj)) {
        console.log(m)
      }
      //keys () 遍历键名。
      console.log(['a', 'b'].keys())
      for (let key of ['a', 'b'].keys()) {
        console.log(key)
      } // 0  // 1
      //values() 遍历值
      for (let key of ['a', 'b'].values()) {
        console.log(key)
      } // a  // b
      // entries()遍历键值对。
      for (let [key, value] of ['a', 'b'].entries()) {
        console.log(key, value)
      }
      // 0 "a"
      // 1 "b"
    </script>
  </body>
</html>
